﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class Admin_Them_moi_bai_viet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetAllTopic();
        }
    }
    protected void GetAllTopic()
    {
        SQLHelper Dal = new SQLHelper();
        Dal.CommandType = CommandType.StoredProcedure;
        Dal.CommandText = "SP_GetAllPostscategories";
        DataTable db = Dal.GetDataTable();
        ddlPostsType.DataSource = db;
        ddlPostsType.DataTextField = db.Columns["TenChuDe"].ToString();
        ddlPostsType.DataValueField = db.Columns["ChuDeID"].ToString();
        ddlPostsType.DataBind();
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        try
        {
            string filename=Path.GetFileName(fuAvatar.FileName);
            fuAvatar.SaveAs(Server.MapPath("~/Images/thumb-news/"+filename));
            SQLHelper Dal = new SQLHelper();
            Dal.Open();
            Dal.CommandType = CommandType.StoredProcedure;
            Dal.CommandText = "SP_AddPost";
            Dal.ParameterCollection = new string[6] { "@TieuDe", "@MoTa", "@NoiDung", "@HinhDaiDien", "@UserEmail", "@ChuDeID" };
            Dal.ValueCollection = new string[6] { txtPostTitle.Text, txtDescription.Text, CKEditorControl1.Text, "Images/thumb-news/"+filename,Session["UserEmail"].ToString(),ddlPostsType.SelectedValue };
            Dal.ExecuteNonQuery();
            Dal.Close();
            Dal.Dispose();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}
